var open = require('open');
var webpack = require('webpack');
var WebpackDevServer = require('webpack-dev-server');
var config = require('./webpack.config');

// 相当于通过本地node服务代理请求到了https://api.mp.tianshunet.com/kongtongapp/
var proxy = [{
    path: '/kongtongapp/*',
    target: 'https://api.mp.tianshunet.com',
    host: 'api.mp.tianshunet.com'
}];

var compiler = webpack(config);
//启动服务
var server = new WebpackDevServer(compiler, {
    publicPath: config.output.publicPath,
    proxy: proxy,
    stats: {
        colors: true
    },
});

//将其他路由，全部返回index.html
server.app.get('*', function (req, res) {
    res.sendFile(__dirname + '/index.html')
});

server.listen(3000);

open('http://localhost:3000', 'chrome');